#include "stdafx.h"
#include "RegistryChecker.h"

CString GetPhotoshopPath(void)
{
    DWORD dwType;
    TCHAR buffer[MAX_PATH];
    DWORD cbSize = sizeof(buffer);
    TCHAR *RegPath[] = {
        _T("SOFTWARE\\Adobe\\Photoshop\\12.0\\ApplicationPath"),
        _T("SOFTWARE\\Adobe\\Photoshop\\11.0\\ApplicationPath"),
        _T("SOFTWARE\\Adobe\\Photoshop\\10.0\\ApplicationPath"),
        _T("SOFTWARE\\Adobe\\Photoshop\\9.0\\ApplicationPath"),
        _T("SOFTWARE\\Adobe\\Photoshop\\8.0\\ApplicationPath"),
    };
    const int CheckCount = 5;

    for (int i = 0; i < CheckCount; i++)
    {
        if (::RegGetValue(HKEY_LOCAL_MACHINE, RegPath[i],
            NULL, RRF_RT_REG_SZ/*RRF_RT_ANY*/, &dwType, buffer, &cbSize) == ERROR_SUCCESS)
        {
            CString path = buffer;
            path += "photoshop.exe";
            return path;
        }
    }

    return _T("");
}

CString GetWordPath(void)
{
    DWORD dwType;
    TCHAR buffer[MAX_PATH];
    DWORD cbSize = sizeof(buffer);
    TCHAR *RegPath[] = {
        _T("SOFTWARE\\Microsoft\\Office\\14.0\\Word\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\13.0\\Word\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\10.0\\Word\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\9.0\\Word\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\8.0\\Word\\InstallRoot"),
    };
    const int CheckCount = 7;

    for (int i = 0; i < CheckCount; i++)
    {
        if (::RegGetValue(HKEY_LOCAL_MACHINE, RegPath[i], _T("Path"), 
            RRF_RT_REG_SZ/*RRF_RT_ANY*/, &dwType, buffer, &cbSize) == ERROR_SUCCESS)
        {
            CString path = buffer;
            path += "winword.exe";
            return path;
        }
    }

    return _T("");
}

CString GetExcelPath(void)
{
    DWORD dwType;
    TCHAR buffer[MAX_PATH];
    DWORD cbSize = sizeof(buffer);
    TCHAR *RegPath[] = {
        _T("SOFTWARE\\Microsoft\\Office\\14.0\\Excel\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\13.0\\Excel\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\12.0\\Excel\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\11.0\\Excel\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\10.0\\Excel\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\9.0\\Excel\\InstallRoot"),
        _T("SOFTWARE\\Microsoft\\Office\\8.0\\Excel\\InstallRoot"),
    };
    const int CheckCount = 7;

    for (int i = 0; i < CheckCount; i++)
    {
        if (::RegGetValue(HKEY_LOCAL_MACHINE, RegPath[i], _T("Path"),
            RRF_RT_REG_SZ/*RRF_RT_ANY*/, &dwType, buffer, &cbSize) == ERROR_SUCCESS)
        {
            CString path = buffer;
            path += "excel.exe";
            return path;
        }
    }

    return _T("");
}

CString GetVCPath(void)
{
    DWORD dwType;
    TCHAR buffer[MAX_PATH];
    DWORD cbSize = sizeof(buffer);
    TCHAR *RegPath[] = {
        _T("SOFTWARE\\Microsoft\\VisualStudio\\10.0\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\10.0Exp\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\9.0Exp\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\8.0Exp\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\7.0\\Setup\\VS"),
        _T("SOFTWARE\\Microsoft\\VisualStudio\\7.0Exp\\Setup\\VS"),
    };
    const int CheckCount = 8;

    for (int i = 0; i < CheckCount; i++)
    {
        if (::RegGetValue(HKEY_LOCAL_MACHINE, RegPath[i], _T("EnvironmentPath"),
            RRF_RT_REG_SZ/*RRF_RT_ANY*/, &dwType, buffer, &cbSize) == ERROR_SUCCESS)
        {
            CString path = buffer;
            return path;
        }
    }

    return _T("");
}

CString GetHtmlPath(void)
{
    return _T("");
}
